/*
 * @Description: 注释
 * @Version: 2.0
 * @Autor: Chen
 * @Date: 2021-12-05 19:35:23
 * @LastEditors: Chen
 * @LastEditTime: 2021-12-08 11:55:49
 */
aesUtil = {
  getKey: function (length = 16) {
    let random = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
    let str = "";
    for (let i = 0; i < length; i++) {
      str = str + random.charAt(Math.random() * random.length)
    }
    return str
  },
  encrypt: function (plaintext, key) {
    if (plaintext instanceof Object) {
      plaintext = JSON.stringify(plaintext)
    }
    let encrypted = CryptoJS.AES.encrypt(CryptoJS.enc.Utf8.parse(plaintext), CryptoJS.enc.Utf8.parse(key), {
      mode: CryptoJS.mode.ECB,
      padding: CryptoJS.pad.Pkcs7
    });
    return encrypted.toString()
  },
  decrypt: function (ciphertext, key) {
    let decrypt = CryptoJS.AES.decrypt(ciphertext, CryptoJS.enc.Utf8.parse(key), {
      mode: CryptoJS.mode.ECB,
      padding: CryptoJS.pad.Pkcs7
    });
    let decString = CryptoJS.enc.Utf8.stringify(decrypt).toString();
    if (decString.charAt(0) === "{" || decString.charAt(0) === "[") {
      decString = JSON.parse(decString)
    }
    return decString
  }
};

signUtil = {
  hashSort: function (arr) {
    const length = arr.length;
    const gap = Math.floor(length / 2);
    while (gap > 1) {
      for (let index = gap; index < length; index++) {
        const temp = arr[index];
        const j = index;
        while (arr[j - gap] > temp && j > gap - 1) {
          arr[j] = arr[j - gap];
          j -= gap;
        }
        arr[j] = temp;

      }
      gap = Math.floor(gap / 2);
    }
  }
}
